<?php
/**
 * Zend Framework Examples
 *
 * @category  Sfs
 * @package   TryIt
 * @author    Michel Corne
 * @copyright 2009 Michel Corne
 * @license   http://www.opensource.org/licenses/bsd-license.php The BSD License
 * @see       http://zend-framework-examples.blogspot.com
 */

/* Displaying items */
class Sfs_Html
{
    /* Displaying the title of the page based on the file name. */
    public static function printTitle()
    {
        $basename = basename(__FILE__, '.php');
        $title = ucwords(str_replace('-' , ' ', $basename));
        $zfVersion = Zend_Version::VERSION;
        $phpVersion = phpversion();
        echo "ZfEx $title (ZF/$zfVersion PHP/$phpVersion)";
    }

    /* Displaying the selected option */
    public static function printSelected($value, $target)
    {
        $value == $target and print 'selected="selected"';
    }

    /* Displaying a check mark */
    public static function printChecked($value)
    {
        empty($value) or print 'checked="checked"';
    }

    /* Colorization of data */
    public static function colorize($mixed)
    {
        // We export the data as valid PHP code.
        $mixed = is_object($mixed)? print_r($mixed, true) : var_export($mixed, true);
        // We add the PHP tag, we colorize the code, we remove the PHP tag.
        $mixed = '<?' . "php $mixed";
        $mixed = highlight_string($mixed, true);
        $mixed = str_replace('&lt;?php&nbsp;', '', $mixed);
        // We display the data.
        echo "<pre>$mixed</pre>";
    }

    /* Extraction of the constants of a class */
    public static function getConstants($class, $prepend = true)
    {
        $reflection = new ReflectionClass($class);
        $constants = $reflection->getConstants();
        ksort($constants);

        if ($prepend) {
            foreach($constants as $name => $value) {
                $prepended["$class::$name"] = $value;
            }
            $constants = $prepended;
        }

        return $constants;
    }
}